﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace W1
{
    public partial class zhir : Form
    {
        public static DataTable dt = new DataTable();
        bool number;
        public zhir()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //取得控件的值
            string a1 = textBox1.Text;

            //非空验证


            if (textBox1.Text == "")
            {
                MessageBox.Show("请正确的输入要查询的姓名");
                return;

            }

            //执行后台

            DataView dv = new DataView(dt);
            dv.RowFilter = string.Format("Username like '%{0}%' ", textBox1.Text);
            dataGridView1.DataSource = dv;

        }

        private void zhir_Load(object sender, EventArgs e)
        {
            string sql = "select  StuNoId,Grade,Classid,Username,Time1,Location1 from  Weareonduty";
            dt = DBHelper.SelectByAdapter(sql);
            dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form8 form8 = new Form8();
            form8.Show();
            this.Hide();
        }

        private void label2_Click(object sender, EventArgs e)
        {
           
        }
        private void button4_Click(object sender, EventArgs e)
        {
            if (DBHelper.str == "0")
            {
            zhir_1 zhir_1 = new zhir_1();
            zhir_1.temp = 2;
            zhir_1.index = dataGridView1.CurrentRow.Index;
            zhir_1.Show();
            }
            else
            {
                button4.Enabled = false;
            }
      
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (DBHelper.str == "0")
            {
                zhir_1 zhir_1 = new zhir_1();         
            zhir_1.temp = 1;
            zhir_1.index = dataGridView1.CurrentRow.Index;
            zhir_1.Show();

            }
            else
            {
                button3.Enabled = false;
            }
         
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (DBHelper.str == "0")
            {
              DialogResult result = MessageBox.Show("您确定要删除此行数据吗？", "删除提示", MessageBoxButtons.YesNo);
             if (result == DialogResult.Yes)
             {
                //取得所选行的索引值（行号）
                int number = dataGridView1.CurrentRow.Index;
                //更新数据库
                string sql = string.Format("delete from Weareonduty where StuNoId='{0}'", dataGridView1.Rows[number].Cells["StuNoId"].Value.ToString());
                bool rlt = DBHelper.ExecuteNonQuery(sql);
                if (rlt)
                {
                    MessageBox.Show("删除成功！");
                }
                //更新画面控件表（移除所选行）
                dataGridView1.Rows.RemoveAt(number);
             }
            }
            else
            {
                button5.Enabled = false;
            }
           
        }

       
    }
}
